home *** CD-ROM | disk | FTP | other *** search
/ PC Player 2004 May / pc player 2004-05.iso / Demos / FarCry / Data1.cab / _152EE27DC7214FD29B615D14863E08C0 < prev    next >
Encoding:
Text File  |  2004-01-06  |  2.3 KB  |  63 lines

  1.       #include "../CGVPMacro.csi"
  2.  
  3.       PS20Only
  4.  
  5.       MainInput { uniform sampler2D baseMap : register(s0),
  6.                   uniform sampler2D bumpMap : register(s1),
  7.                   uniform sampler3D noiseMap : register(s2),
  8.                   uniform float4 Diffuse,
  9.                   uniform float4 Specular,
  10.                   uniform float4 Ambient,
  11.                   uniform float4 GlitterParms }
  12.       DeclarationsScript
  13.       {
  14.         OUT_T0_T1_T2_T3_T4_T5
  15.         FOUT
  16.       }
  17.       CoreScript
  18.       {
  19.         // load the decal
  20.         float4 decalColor = tex2D(baseMap, IN.Tex0.xy);
  21.         // load the bump normal
  22.         float4 bumpNormal = 2*(tex2D(bumpMap, IN.Tex1.xy)-0.5);
  23.  
  24.         float3 pos = IN.Tex4.xyz;
  25.         float noisy = tex3D(noiseMap, pos*0.4).a;
  26.  
  27.         // Extract some random points to glitter.
  28.         // This is done by perturbing a grid pattern with some noise and
  29.         // with the view-vector to let the glittering change with view.
  30.         float3 fp = frac(GlitterParms.x * pos.xyz + 9 * noisy + GlitterParms.y * IN.Tex5.xyz);
  31.         fp *= (1 - fp);
  32.         float glitter = saturate(1 - GlitterParms.w * (fp.x + fp.y + fp.z));
  33.  
  34.         // normalize post-filtered bump normals
  35.         bumpNormal.xyz = normalize(bumpNormal.xyz);
  36.  
  37.         // normalize light vector
  38.         float3 lightVec = normalize(IN.Tex2.xyz);
  39.         float fDif = saturate(dot(lightVec.xyz, bumpNormal.xyz));
  40.  
  41.         // normalize view vector
  42.         float3 viewVec = normalize(IN.Tex3.xyz);
  43.         float3 reflVec = (2*dot(lightVec.xyz, bumpNormal.xyz)*bumpNormal.xyz)-lightVec.xyz;
  44.         float NdotR = saturate(dot(reflVec.xyz, viewVec.xyz));
  45.         float fSpec = pow(NdotR, Specular.w);
  46.  
  47.         // Only glitter around the specular highlight. We use a lower
  48.         // exponent for the glitter to let it spread more.
  49.         float glittering = glitter * pow(NdotR, 2);
  50.  
  51.         // Get a little more interesting base color
  52.         decalColor.xyz = (0.5 * noisy + 0.5) * decalColor.xyz;
  53.  
  54.         float3 dif = (decalColor.xyz * fDif * Diffuse.xyz) * 2;
  55.         float3 spec = (fSpec * Specular.xyz) * 2;
  56.         float3 amb = Ambient.xyz * decalColor.xyz;
  57.  
  58.         // finally add them all together
  59.         OUT.Color.xyz = amb + dif + spec + glittering*GlitterParms.z;
  60.         OUT.Color.w = decalColor.w * Ambient.w;
  61.       }
  62.  
  63.